﻿/*
素数的各位数字和 
Time Limit:1000MS  Memory Limit:32768K


Description:
你的任务首先是判断是否素数，若为素数，则要求该素数的各位数字和。

Input:
输入中有若干正整数（<300000）。 
Output:
对于每个整数，若不是素数，则输出0，否则，输出该素数的各位数字和。 
Sample Input:
9 7 5 11 101 329 313 2 12 8
Sample Output:
0
7
5
2
2
0
7
2
0
0
*/
#include <stdio.h>
#include <stdlib.h>
static const unsigned PRIMES[] =
{
	2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67,
	71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113, 127, 131, 137, 139, 149,
	151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199, 211, 223, 227, 229,
	233, 239, 241, 251, 257, 263, 269, 271, 277, 281, 283, 293, 307, 311, 313,
	317, 331, 337, 347, 349, 353, 359, 367, 373, 379, 383, 389, 397, 401, 409,
	419, 421, 431, 433, 439, 443, 449, 457, 461, 463, 467, 479, 487, 491, 499,
	503, 509, 521, 523, 541, 547, 557
};
int main(int argc, char* argv[])
{
	char input[8];
	size_t primes_length = sizeof(PRIMES) / sizeof(PRIMES[0]);
	while (EOF != scanf("%s", input))
	{
		unsigned long num = atol(input);
		size_t i = 0u;
		bool is_prime = true;
		for (; PRIMES[i] * PRIMES[i] <= num && i < primes_length; ++i)
			if (0 == num % PRIMES[i])
			{
				is_prime = false;
				break;
			}
		if (is_prime)
		{
			unsigned sum = 0u;
			for (const char*p = input; *p; ++p)
				sum += *p - '0';
			printf("%u\n", sum);
		}
		else
			printf("0\n");
	}
	return EXIT_SUCCESS;
}